﻿/**
 * $HeadURL: http://smartcollector.googlecode.com/svn/branches/Srcs/SmartCollector.WebUI/SmartCollector.WebUI/Controllers/ItemController.cs $
 * $Author: ntt.cse $
 * $Date: 2011-05-12 00:47:23 +0000 (Thu, 12 May 2011) $
 * $Rev: 118 $
 **/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SmartCollector.WebUI.Models;
using SmartCollector.WebUI.Helpers;

namespace SmartCollector.WebUI.Controllers
{
    public class ItemController : Controller
    {
        private const int DefaultPagesize = 10;
        ItemRepository item=new ItemRepository();
        //
        // GET: /Item/
        public ActionResult Index()
        {
            ViewData["topnews"] = item.GetTopNewsAfterOne();
            ViewData["onenews"] = item.GetOneItem();
            ViewData["r_docnhieunhat"] = item.GetTindocnhieu();
            return View();
        }

        public ActionResult News(int id,int? page)
        {
            int currentPageIndex = page.HasValue ? page.Value : 1;
            IQueryable<tbl_Item> i=null;
            tbl_Category c = null;
            ViewData["singleitem"] = item.GetNewItemByCateId(id);
            c= item.GetSingleCategoriesById(id);
            if (c.ParentID != null)
            {
                ViewData["catId"] = c.ParentID;
            }
            else
            {
                ViewData["catId"] = c.ID;
            }
            i=item.GetItemFromCategory(id);
            
            return View(i.ToPagedList(currentPageIndex, DefaultPagesize));
        }

        public ActionResult Details(int id)
        {
            tbl_Item it = item.GetItemById(id);
            if (it.tbl_Category.ParentID != null)
            {
                ViewData["catId"] = it.tbl_Category.ParentID;
            }
            else
            {
                ViewData["catId"] = it.CategoryID;
            }
            if (it == null)
                return View("Error");
            return View(it);
        }
    }
}
